home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 66
/
Vol 66.iso
/
games
/
bob_espo.swf
/
scripts
/
__Packages
/
CTRLGame.as
< prev
next >
Wrap
Text File
|
2013-04-24
|
14KB
|
447 lines
class CTRLGame
{
static var nOUT_POS_BTN_CACHE = -400;
static var nPOWERUP_BONUS_POINTS = 0;
static var nPOWERUP_GOOD_NOTE = 1;
static var nPOWERUP_FALSE_NOTE = 2;
static var nTURN_WALL = 0;
static var nTURN_WALL_INVERSE = 1;
static var nSLIDE_WALL_H = 2;
static var nSLIDE_WALL_V = 3;
static var nREVOLVER_WALL = 4;
static var nDIR_LEFT = 0;
static var nDIR_UP = 1;
static var nDIR_RIGHT = 2;
static var nDIR_DOWN = 3;
static var nLEVEL1 = 1;
static var nLEVEL2 = 2;
static var nDUMMY_DEPTH = 999999;
static var nMIN_DEPTH = 100012;
static var nDEPTH_FACTOR = 100;
static var nDIRT_WALL_ADD = 1;
static var nMOVING_WALL_ADD = 25;
static var nALGAE_ADD = 50;
static var nBUS_ADD = 76;
static var nJELLYFISH_ADD = 100;
static var nNB_THROW_SOUNDS = 5;
function CTRLGame(_mcRef, _nScore, _nLevel)
{
this.mcRef = _mcRef;
CTRLGame.oRef = this;
this.nScore = _nScore;
this.nCurrentLevel = _nLevel;
this.initLevel();
}
function cleanUp()
{
this.oGenerator.cleanUp();
this.oAtlantisBus.cleanUp();
this.oCenterScreen.cleanUp();
for(var i in this.aWalls)
{
this.aWalls[i].cleanUp();
}
for(var i in this.aDirtWalls)
{
for(var j in this.aDirtWalls[i])
{
this.aDirtWalls[i][j].cleanUp();
}
}
for(var i in this.aJellys)
{
this.aJellys[i].cleanUp();
}
for(var i in this.aAlguaes)
{
for(var j in this.aAlguaes[i])
{
this.aAlguaes[i][j].cleanUp();
}
}
delete this.oGenerator;
delete this.oAtlantisBus;
delete this.oCenterScreen;
}
function addObjectViaDummy(_mcDummy)
{
var _loc3_ = new Object();
_loc3_.x = 0;
_loc3_.y = 0;
_loc3_.x = _mcDummy._x;
_loc3_.y = _mcDummy._y;
_mcDummy._parent.localToGlobal(_loc3_);
_mcDummy.swapDepths(CTRLGame.nDUMMY_DEPTH);
_mcDummy.removeMovieClip();
return _loc3_;
}
function countdownPushBusGames()
{
if(this.nNbPushBusSandyLeft > 0)
{
this.nNbPushBusSandyLeft = this.nNbPushBusSandyLeft - 1;
}
}
function modifyTime(_nNewValue)
{
this.nSongsNumber = _nNewValue;
}
function blockEvents()
{
this.mcRef.mcCache._y = 0;
this.mcRef.mcShadow._visible = true;
}
function unBlockEvents()
{
this.mcRef.mcCache._y = CTRLGame.nOUT_POS_BTN_CACHE;
this.mcRef.mcShadow._visible = false;
}
function addToScore(_nNumber)
{
this.nScore += _nNumber;
Main.getRef().updateScoreField();
}
function substractToScore(_nNumber)
{
this.nScore -= _nNumber;
Main.getRef().updateScoreField();
}
function calculateDepth(_nY, _nAdd)
{
var _loc4_ = Math.round(_nY) * CTRLGame.nDEPTH_FACTOR + _nAdd + CTRLGame.nMIN_DEPTH;
return _loc4_;
}
function stopAnimElements()
{
for(var i in this.aDirtWalls)
{
for(var j in this.aDirtWalls[i])
{
this.aDirtWalls[i][j].doPause();
}
}
for(var i in this.aJellys)
{
this.aJellys[i].doPause();
}
for(var i in this.aAlguaes)
{
for(var j in this.aAlguaes[i])
{
this.aAlguaes[i][j].doPause();
}
}
this.oAtlantisBus.doPause();
}
function resumeAnimElements()
{
for(var i in this.aDirtWalls)
{
for(var j in this.aDirtWalls[i])
{
this.aDirtWalls[i][j].resumeAnim();
}
}
for(var i in this.aJellys)
{
this.aJellys[i].resumeAnim();
}
for(var i in this.aAlguaes)
{
for(var j in this.aAlguaes[i])
{
this.aAlguaes[i][j].resumeAnim();
}
}
this.oAtlantisBus.resumeAnim();
}
function addPowerUp(_nType, _mcItem)
{
var _loc4_ = new Object();
_loc4_.mcRef = _mcItem;
_mcItem._xscale = _mcItem._parent._parent._xscale;
_loc4_.nType = _nType;
var _loc5_ = this.oGenerator.getTabIndexByName(_mcItem._parent._parent._name);
this.aItems[_loc5_].push(_loc4_);
}
function addDirtWall(_mcDummy)
{
var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
var _loc4_ = this.addObjectViaDummy(_mcDummy);
this.aDirtWalls[_loc3_].push(new DirtWall(_loc4_.x,_loc4_.y));
}
function addJellyFish(_mcDummy)
{
var _loc3_ = this.addObjectViaDummy(_mcDummy);
this.aJellys.push(new RoamingJellyFish(_loc3_.x,_loc3_.y));
}
function addAlgae(_mcDummy)
{
var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
var _loc4_ = this.addObjectViaDummy(_mcDummy);
this.aAlguaes[_loc3_].push(new Algae(_loc4_.x,_loc4_.y));
}
function addActionWall(_nType, _mcDummy, _xScl)
{
var _loc5_ = this.addObjectViaDummy(_mcDummy);
this.aWalls.push(new ActionWall(_nType,_loc5_.x,_loc5_.y,_xScl));
}
function checkPowerUps()
{
var _loc2_ = this.oAtlantisBus.mcRef;
var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
var _loc4_ = this.aItems[_loc3_];
for(var i in _loc4_)
{
if(_loc4_[i].mcRef.hitTest(_loc2_._x,_loc2_._y,true))
{
this.activatePowerUp(_loc4_[i].nType,_loc4_[i].mcRef);
delete _loc4_[i];
_loc4_.splice(Number(i),1);
break;
}
}
}
function checkDirtWalls()
{
var _loc2_ = this.oAtlantisBus.mcRef;
var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
var _loc4_ = this.aDirtWalls[_loc3_];
for(var i in _loc4_)
{
if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_.mcHit))
{
this.oCenterScreen.startBreakTheWall(_loc4_[i]);
_loc4_.splice(Number(i),1);
break;
}
}
}
function checkJellys()
{
var _loc2_ = this.oAtlantisBus.mcRef;
for(var i in this.aJellys)
{
if(this.aJellys[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
{
this.aJellys[i].stopRoaming();
this.oCenterScreen.startJellyFishSwarm(this.aJellys[i]);
this.aJellys.splice(Number(i),1);
break;
}
}
}
function checkAlgaes()
{
var _loc2_ = this.oAtlantisBus.mcRef;
var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
var _loc4_ = this.aAlguaes[_loc3_];
for(var i in this.aAlguaes)
{
if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
{
_loc4_[i].catchBus();
var _loc5_ = true;
if(this.nNbPushBusSandyLeft <= 0)
{
_loc5_ = false;
}
this.oCenterScreen.startPushTheBus(_loc4_[i],_loc5_);
_loc4_.splice(Number(i),1);
break;
}
}
}
function checkFinish()
{
var _loc2_ = this.oAtlantisBus.mcRef;
if(this.mcRef.mcStart.piece.mcFinish.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) && !Main.getRef().Finished)
{
Main.getRef().winGame();
}
}
function isOkayToTurn(_mcHit)
{
var _loc3_ = true;
if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))
{
_loc3_ = false;
}
if(_loc3_)
{
for(var i in this.aJellys)
{
if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))
{
_loc3_ = false;
break;
}
}
}
return _loc3_;
}
function isOkayToTurnRevolver(_mcHit, _mcHitMore)
{
var _loc4_ = true;
if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || (_mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true) || (_mcHitMore.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHitMore.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))))
{
_loc4_ = false;
}
if(_loc4_)
{
for(var i in this.aJellys)
{
if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || (_mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true) || (_mcHitMore.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHitMore.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))))
{
_loc4_ = false;
break;
}
}
}
return _loc4_;
}
function isTouchingWall(_nFutureX, _nFutureY)
{
var _loc4_ = false;
for(var i in this.aWalls)
{
var _loc5_ = this.aWalls[i];
if(_loc5_.Type == CTRLGame.nREVOLVER_WALL)
{
if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true) || _loc5_.Ref.mcHitMore.hitTest(_nFutureX,_nFutureY,true))
{
_loc4_ = true;
break;
}
}
else if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true))
{
_loc4_ = true;
break;
}
}
return _loc4_;
}
function isJellyTouchingDirtWall(_nFutureX, _nFutureY)
{
var _loc4_ = false;
var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
var _loc6_ = this.aDirtWalls[_loc5_];
for(var i in _loc6_)
{
if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
{
_loc4_ = true;
break;
}
}
return _loc4_;
}
function isJellyTouchingAlguae(_nFutureX, _nFutureY)
{
var _loc4_ = false;
var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
var _loc6_ = this.aAlguaes[_loc5_];
for(var i in _loc6_)
{
if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
{
_loc4_ = true;
break;
}
}
return _loc4_;
}
function isJellyTouchingJelly(_nFutureX, _nFutureY, _oJelly)
{
var _loc5_ = false;
for(var i in this.aJellys)
{
if(this.aJellys[i] != _oJelly)
{
if(this.aJellys[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
{
_loc5_ = true;
break;
}
}
}
return _loc5_;
}
function get Screen()
{
return this.oCenterScreen;
}
function get Bus()
{
return this.oAtlantisBus;
}
function get Maze()
{
return this.oGenerator;
}
function get Songs()
{
return this.nSongsNumber;
}
function get Level()
{
return this.nCurrentLevel;
}
function get Score()
{
return this.nScore;
}
static function getRef()
{
return CTRLGame.oRef;
}
function activatePowerUp(_nType, _mcPowerUp)
{
switch(_nType)
{
case CTRLGame.nPOWERUP_BONUS_POINTS:
Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
this.addToScore(LD.nBONUSPOINTS);
_mcPowerUp.swapDepths(7777);
_mcPowerUp.removeMovieClip();
break;
case CTRLGame.nPOWERUP_FALSE_NOTE:
Controller.getRef().getSounds().playSound("BadPowerUp_Collect",Controller.nSFX_VOLUME,1);
CTRLGame.getRef().Screen.getInterface().setToLife(LD.nFALSE_NOTE_VALUE);
_mcPowerUp.swapDepths(7777);
_mcPowerUp.removeMovieClip();
break;
case CTRLGame.nPOWERUP_GOOD_NOTE:
Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
CTRLGame.getRef().Screen.getInterface().setToLife(LD.nGOOD_NOTE_VALUE);
_mcPowerUp.swapDepths(7777);
_mcPowerUp.removeMovieClip();
}
}
function winGame()
{
CTRLGame.getRef().Screen.getInterface().pauseTime();
Main.getRef().winGame();
}
function loseGame()
{
CTRLGame.getRef().Screen.getInterface().pauseTime();
Main.getRef().loseGame();
}
function initLevel()
{
this.aItems = [[],[],[],[],[],[],[],[],[],[]];
this.aWalls = new Array();
this.aAlguaes = [[],[],[],[],[],[],[],[],[],[]];
this.aDirtWalls = [[],[],[],[],[],[],[],[],[],[]];
this.aJellys = new Array();
this.nNbPushBusSandyLeft = LD.nNB_PUSHBUS_WITH_SANDY;
this.nSongsNumber = LD.getSongsMax(this.nCurrentLevel);
this.oGenerator = new MazeGenerator(this.mcRef);
this.oCenterScreen = new CenterScreen(this.mcRef.mcCenter);
this.oGenerator.generate();
this.oAtlantisBus = new AtlantisBus();
}
}